package com.example.mongodb;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Administrator on 2017/1/16 0016.
 */

@RestController
public class MongoDemoController {


    @Autowired
    private MongoDemoInfoRepository demoInfoRepository;

    @RequestMapping("savemg")
    public String save(){
        MongoDemoInfo demoInfo = new MongoDemoInfo();
        demoInfo.setName("张三");
        demoInfo.setAge(20);
        demoInfoRepository.save(demoInfo);

        demoInfo = new MongoDemoInfo();
        demoInfo.setName("李四");
        demoInfo.setAge(30);
        demoInfoRepository.save(demoInfo);

        return "ok";
    }

    @RequestMapping("findmg")
    public List<MongoDemoInfo> find(){
        return demoInfoRepository.findAll();
    }

    @RequestMapping("findByNamemg")
    public MongoDemoInfo findByName(){
        return demoInfoRepository.findByName("张三");
    }


}
